<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>外边距</title>
  <style>
    * {
      margin: 0;
      padding: 0;
    }

    .box1 {
      width: 400px;
      height: 400px;
      background-color: green;
      overflow: auto;
      padding: 40px;
      /* 设置宽度和高度向内缩 */
      box-sizing: border-box;
    }

    .box2 {
      width: 200px;
      height: 100px;
      background-color: pink;
    }

    .box3 {
      width: 300px;
      height: 150px;
      background-color: red;
    }
  </style>
</head>

<body>
  <div class="box1">
    <div class="box2"></div>
    <div class="box3"></div>
  </div>
</body>

</html>